package de.tabuma.shopping.controller;

import de.tabuma.shopping.*;
import de.tabuma.shopping.entity.*;
import de.tabuma.shopping.logik.*;
import de.tabuma.lib.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.google.appengine.api.users.*;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.2 $
 * @since $Date: 2009/07/21 19:37:32 $
 */
public class orderOverview extends tabumacontroller {

    private static Logger log =  Logger.getLogger(description.class.getName());

    LicensePackageFacade licensePackageFacade;
    List<LicenseType> licenseTypeList;
    private Class assignmentClass;
    private Field assignmentKey;
    private Field assignmentShow;
    private List assignmentList;
    private String assignmentObjectname;
    private Hashtable<Integer,String> methodList;

    public orderOverview(String servlet, Hashtable parameter, LicensePackageFacade licensePackageFacade, List<LicenseType> licenseTypeList, Class assignmentClass, Field assignmentKey, Field assignmentShow, List assignmentList, String assignmentObjectname, Hashtable<Integer,String> methodList) {
        super(servlet, parameter);
        this.licensePackageFacade = licensePackageFacade;
        this.licenseTypeList = licenseTypeList;
        this.assignmentClass = assignmentClass;
        this.assignmentKey = assignmentKey;
        this.assignmentShow = assignmentShow;
        this.assignmentList = assignmentList;
        this.assignmentObjectname = assignmentObjectname;
        this.methodList = methodList;
    }

    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out)  {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        List<LicensePackage> list1 = licensePackageFacade.getAllLicensePackageList();
        request.setAttribute("LicensePackageList", list1);

        List<Order> myList = OrderFacade.getOrderList(user.getEmail());
        request.setAttribute(constants.ORDER_LIST, myList);

        List<OrderLicensePackageRelation> olprs = new ArrayList<OrderLicensePackageRelation>();
        for(int i=0;i<myList.size();i++) {
            olprs.addAll(OrderLicensePackageRelationFacade.getList(myList.get(i).getId().intValue()));
        }
        request.setAttribute(constants.ORDER_LICENSEPACKAGERELATION_LIST, olprs);
        licenseassignmenttable lat = new licenseassignmenttable(this.getServlet(), this.getParameter(), this.licensePackageFacade, licenseTypeList, this.assignmentClass, this.assignmentKey, this.assignmentShow, this.assignmentList, this.assignmentObjectname, this.methodList);
        lat.navigate(context, request, response, out);
    }
}